<?
layout("/inc/layout.html",{title:sysTitle}){
?>

<div id="page-wrapper">
	<!--BEGIN TITLE & BREADCRUMB PAGE-->
	<div id="title-breadcrumb-option-demo" class="page-title-breadcrumb">
		<div class="page-header pull-left">
			<div class="page-title">${name}</div>
		</div>
		<div class="clearfix"></div>
	</div>
	<!--END TITLE & BREADCRUMB PAGE-->
	<!--BEGIN CONTENT-->
	<div class="page-content">


		<div class="row mbl" >
			<div class="col-lg-10">
				<table style="width: 100%;">
					<tr height="50">
						<td align="right" style="width: 100px;">卷子名称:&nbsp;&nbsp;</td>
						<td><input type="text"  class="form-control" id="name" name="name" /></td>
						<td align="right" style="width: 100px;">卷子描述:&nbsp;&nbsp;</td>
						<td><input type="text"  class="form-control" id="description" name="description" /></td>
						<td align="left" style="width: 100px;"><button type="button" data-toggle="dropdown" class="btn btn-blue dropdown-toggle" onclick="get()">查询</button></td>
						<td align="left" style="width: 100px;"><button type="button" data-toggle="dropdown" class="btn btn-blue dropdown-toggle" onclick="paperDetail('0')">创建试卷</button></td>
						<td align="left" style="width: 100px;"><button type="button" data-toggle="dropdown" class="btn btn-blue dropdown-toggle" onclick="backpage()"><i class="fa fa-mail-reply-all">&nbsp;</i>返回</button></td>
					</tr>
				</table>
			</div>
		</div>

		<table
			class="table table-hover table-striped table-bordered table-advanced tablesorter mbn">
			<thead>
				<tr>
					<th> <input type="checkbox" onclick="selectAll(this)" class="checkall" name="oncheckall" /></th>
					<th>序号</th>
					<th>试卷名称</th>
					<th>考试开始时间</th>
					<th>考试结束时间</th>
					<th>卷子描述</th>
					<th>创建时间</th>
					<th>可操作</th>
				</tr>
			</thead>
			<tbody id="findUser">
			</tbody>
		</table>
		<div id="page2" style="text-align: center; margin-top: 20px;"></div>
		<div id="dataNull" class="panel-body"
				style="height: 90px; line-height: 50px;" align="center">
		</div>
		<input type="hidden" id="id" value="${id}">
		<input type="hidden" id="type" value="${type}">
	</div>
	<!--END CONTENT-->
</div>


<?} ?>
<script>
	var curr;
	$(function() {
		demo1(1);
	});
	function get() {
		demo1(curr);
	}
	function del(id) {
		if (confirm("是否确认删除！！"))
		{
			$.ajax({
				type : "post",
				url : "./paperDel.do",
				data : {
					"id" : id,
				},
				dataType : "json",
				success : function(data) {
					if(data[0].result=='success'){
						demo1(curr);
					}
					layer.msg(data[0].msg);
				},
				error : function(data) {
					alert("请求失败");
				}
			});
		}
	}
	function demo1(cur) {
		$.getJSON("./paperList.do",
			{
				page : cur || 1,
				name:$("#name").val(),
        		description:$("#description").val(),
        		resourceId:$("#id").val(),
        		type:$("#type").val(),
			},
			function(res) {
				//此处仅仅是为了演示变化的内容
				var str = "";
				$("#findUser").html("");
				if(res.listsize>0){
					$("#dataNull").html("");
				}else{
					$("#dataNull").html("<span class='subtitle' style='font-size: 15px;'>数据为空!</span>");
				}
				for ( var i = 0; i < res.listsize; i++) {
					str += "<tr><td>"
							+ '<input name="checkall" type="checkbox"/>'
							+ '</td><td>'
							+ (i + 1)
							+ "</td><td> <label>"
							+ res.result[i].name
							+ "</label></td><td><label >"
							+ res.result[i].startTime
							+ "</label></td><td><label >"
							+ res.result[i].endTime
							+ "</label></td><td><label >"
							+ res.result[i].description
							+ "</label></td><td><label >"
							+ res.result[i].createTime
							+ "</label></td><td>"
							+ "<button type=\"button\" class=\"btn btn-green btn-xs\"onclick=\"paperDetail('"
							+ res.result[i].id
							+ "')\">"
							+ "编辑"
							+ "</button>&nbsp;"
							+ "<button type=\"button\" class=\"btn btn-red btn-xs\"onclick=\"del('"
							+ res.result[i].id
							+ "')\">"
							+ "删除"
							+ "</button>&nbsp;"
							+ "<button type=\"button\" class=\"btn btn-blue btn-xs\"onclick=\"zujuanzi('"
							+ res.result[i].id+"','"+res.result[i].name
							+ "')\">"
							+ "组卷子"
							+ "</button>&nbsp;"
							+ "</td></tr>";
				}
				$("#findUser").html(str);

				laypage({
					cont : document.getElementById('page2'), //容器。值支持id名、原生dom对象，jquery对象,
					pages : res.pageSize, //总页数
					skip : true, //是否开启跳页
					skin : 'molv', //加载内置皮肤，也可以直接赋值16进制颜色值，如:#c00
					curr: cur || 1,
					last: res.pageSize,
					groups : 6,//连续显示分页数
					jump : function(obj, first) { //触发分页后的回调
						if (!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
							demo1(obj.curr);
			                 curr=obj.curr;
						}
					}
				});
			});
	};




function paperDetail(id) {
	layer.open({
		type : 2,
		area : [ '600px', '650px' ],
		fix : false, //不固定
		scrollbar : false,
		shadeClose : true,
		//move : false,
		title:"创建试卷",
		skin : 'layui-layer-rim', //加上边框
		btn : [ '保存 ', '关闭' ],
		content : ["paper-detail.html?id="+id+"&type="+$("#type").val()+"&resourceId="+$("#id").val()+"&winName="+window.name, 'no'],
		yes : function(index,layer) {		
		 var iframeWin = parent.window[layer.find('iframe')[0]['name']];
		  			  iframeWin.save();
		},
		cancel : function(index) {
		}
	});
}
function zujuanzi(id,name) {
	layer.open({
		type : 2,
		area : [ '95%', '80%' ],
		fix : false, //不固定
		scrollbar : true,
		shadeClose : true,
		//move : false,
		title:"组卷子>"+name,
		skin : 'layui-layer-rim', //加上边框
		btn : [ '关闭' ],
		content : ["teacher-zujuanzi.html?id="+id+"&type="+$("#type").val()+"&resourceId="+$("#id").val()+"&winName="+window.name, 'no'],
		cancel : function(index) {
		}
	});
}
function backpage(){
	if($("#type").val()=='0'){//课程
		window.location.href = "kecheng-teacher.html";
	}else if($("#type").val()=='1'){//微课
		window.location.href = "weike-teacher.html";
	}else if($("#type").val()=='2'){//直播
		window.location.href = "zhibo-teacher.html";
	}
	
}
</script>